# info1 = "D:\tools\noco"
# print(info1)

# 通过位置（下标）找元素
# info = "abcdefg"
# # 获取字母b
# print(info[1])
# # 通过元素找下标位置，字母e的位置
# print(info.find("e"))
# # 字母K的位置，如果找不到返回-1
# print(info.find("k"))
#
# # 字符串替换
# info1 = "金三胖同志被称之为世界最成功的80后，金三胖真牛！"
# # 使用字符串替换，语法格式：字符串名.replace("原字符串","新字符串")
# info2 = info1.replace("金三胖","马赛克")
# print(info2)
# print(info1)

# 字符串链接，语法格式：链接字符.join(列表/元组/集合)
# info = ['python','java','PHP']
# num = [11,22,33]
# # 链接
# info1 = "and".join(info)
# print(info1)
# print(type(info1))
#
# sql = "SelECt * from students where id = 001";
# print(sql.split()) #结果类型是列表
# for i in sql.split():
#     print(i)
# # 上述SQL按照where拆分出来
# print(sql.split("where"))
#
# # 字符串中字母大小转换,转大写(字符串.upper()),转小写（字符串.lower())
# # 判断是否是字母/数字，字母（字符串.isalpha()),数字（字符串.isdigit())
# # 判断某个字符出现的次数：字符串.count("字符")
# # 字符串两头去除空格,变量.strip
# phone = " 13800000001 "
# print(phone)
# print(phone.strip())
#
# sql = "SelECt * from students where id = 001;"
# # 判断是否是查询（查询是否存在）
# if "select" in sql.lower():
#     print("显示查询结果")
# else:
#     print("非查询")

# 案例
# phone = input("请输入手机号：").strip()
# password = input("请输入密码：").strip()
# code = input("请输入验证码：").strip().lower()
# 判断是否为空
# if username == "":
#     print("手机号不能为空！")
# if password == "":
#     print("密码不能为空！")
# if code == "":
#     print("验证码不能为空！")
# if len(username) != 11 or not (username.isdigit()):
#     print("手机号码不正确")
# if code.lower() != "8888":
#     print("验证码错误")
# if password != "123456":
#     print("密码错误")
# if username == "13488888888" and password == "123456" and code == "8888":
#     print("登录成功")
# 方式2
# if phone == "":
#     print("手机号不能为空")
# else: # 不为空是进一步判断(长度不对/类型不对)
#     if len(phone) != 11 or not phone.isdigit():
#         print("手机号格式错误")
#     elif phone != "13488888888":
#         print("手机号不存在")
#
# if phone == "13488888888":
#     if password == "":
#         print("密码不能为空")
#     elif password != "123456":
#         print("密码与账号不匹配")
#     elif password == "123456":
#         if code == "8888":
#             print("登录成功")
#         else:
#             print("验证码错误")
# else:
#     print("数据输入不正确")

# 列表的定义
# info = []
# info1 = list()
# print(info)
# print(info1)
# # 定义非空列表
# info2 = [11,"aaa",1.88]
# print(info2)

# # 定义列表
# data_list = ['python', 'java', 'python', 'php']
# # 统计python出现的次数
# num = data_list.count("python")
# print(num) # 次数：2
# # 统计java出现次数
# print(data_list.count("java")) # 次数：1
# print(data_list.count("C++")) # 次数：0
#
# # 定义列表
# val_list = ["Web自动化", "UI自动化", "接口自动化"]
# # 添加元素（末尾添加：APP自动化）
# val_list.append("APP自动化")
# # 查看原来列表
# print(val_list)
# # 增加数字元素
# val_list.append(11)
# print(val_list)

# 定义列表
# val_list = ["Web自动化", "UI自动化", "接口自动化"]
# val_list.insert(1,"APP自动化")
# print(val_list)
# # 在列表第七个位置添加元素“Java”
# val_list.insert(6,"java")
# print(val_list)

# 列表合并
# info1 = [1,2,3]
# info2 = [4,5,6]
# info1.extend(info2)
# print(info1)
# print(info2)

# # 列表元素删除，指定索引位置删除
# val_list = ["Web自动化","APP自动化", "UI自动化", "接口自动化","Java"]
# # 删除下标为2对应元素
# val_list.pop(2)
# print(val_list)
# val_list.pop()
# print(val_list)

# # 指定数据删除
# val_list = ["Web自动化","APP自动化", "UI自动化", "接口自动化","Java"]
# # 删除“APP自动化”
# # val_list.remove('APP自动化')
# print(val_list)
# # 删除'java'
# val_list.remove('Java')
# print(val_list)

# 元素修改
# val_list = ["Web自动化","APP自动化", "UI自动化", "接口自动化","Java"]
# val_list[1] = "性能自动化"
# print(val_list)
# val_list[4] = "python"
# print(val_list)

# 元素反转
# info = [8,122,30,20,2]
# info.reverse()
# print(info)

# 元素大小排列
# info1 = [8,6,12,49,30]
# # 从小排到大
# info1.sort()
# info1.sort(reverse=False)
# print(info1)
# # 从大排到小
# info1.sort(reverse=True)
# print(info1)

# 列表嵌套
# 定义列表
# student_list = [["张三", "18", "功能测试"], ["李四", "20", "自动化测试"], ["王五", "22",["python", "java"]]]
# 获取指定的元素
# print(student_list[0])
# aa = student_list[0]
# print(aa[1])
# 合并起来
# print(student_list[0][1])
# 查找李四
# print(student_list[1][0])
# 查找java
# print(student_list[2][2][1])

# 定义非空列表(把每种测试结果的数据放在一起)
# login_data = [
#     ["13488888888", "123456", "8888"],
#     ["13488888888", "666666", "8888"],
#     ["13488888880", "123456", "8888"],
#     ["13488888888", "123456", "0000"]
#     ]
# 遍历
# for i in login_data:
# 判断手机号和密码
#     if i[0] == "13488888888" and i[1] == "123456":
#     # 判断验证码
#         if i[2] == "8888":
#             print("登录成功")
#         else:
#             print("验证码错误")
#     else:
#         print("用户名或密码错误")

# 定义空元组
# info = ()
# info1 = tuple()
# print(info)
# print(info1)
# 非空
# info2 = (11, 22, 33, 44)
# print(info2)
# 单个元素>
# info3 = ("55",)
# print(type(info3))
# 不写括号
# info4 = 1, 2, 3, 4
# print(type(info4))


# 定义元组
# info = (11, "aaa", 1.88)
# 查看下标为2对应元素
# print(info[2])
# 查看下标为4对应元素
# print(info[4])


# 定义变量
# num1 = 100
# num2 = 200
# 交换两个数据
# 方式1：找第三个变量，进行互换
# tmp = num1
# num1 = num2
# num2 = tmp
# print("此时num1的值：", num1)
# print("此时num2的值：", num2)
# 方式2：直接借助于python元组类型的数据直接替换
# aa = 200 # 相当于把200给aa
# bb = 100 # 相当于把100给bb
# num1 = aa
# num2 = bb
# 合并结果 # num1, num2 = 200, 100
# num1, num2 = num2, num1
# print("此时num1的值：", num1)
# print("此时num2的值：", num2)

# 定义空字典
# info = {}
# info1 = dict()
# print(type(info), type(info1))
# print(info)
# 非空字典
# info2 = {"name": "张三", "age": 22, "height": 1.88}
# print(info2)
# print(type(info2))


# 定义非空字典
# info = {"name": "张三"}
# # 将张三修改为李四
# info["name"] = "李四"
# # 查看原有字典
# print(info)
# # 增加年龄为22岁
# info["age"] = 22
# # 查看原有字典
# print(info)


# 定义字典
# info = {'name': '李四', 'age': 22}
# # 删除年龄22
# info.pop("age")
# # 查看原来字典
# print(info)

# 定义非空字典
# info = {"name": "tom",
#         "age": 18,
#         "gender": "男",
#         "hobby": {"read": "小说", "sport": ["篮球", "足球"]}
#         }
# 查询年龄
# a1 = info["age"]
# print(a1)
# print(info["age"])
# print(info.get("age"))
# # 查询键aa的值
# print(info.get("aa"))
# # 思考：如何获取值："足球"
# # 组合:从外部一层一层获取递进
# print(info["hobby"]["sport"][1])
# print(info.get("hobby").get("sport")[1])

# 字典的合并/新增
# 定义字典1
# dict1 = {"name": "张三", "age": 18}
# # 定义字典2
# dict2 = {"height": 1.88}
# # 将字典2合并到字典1
# dict1.update(dict2)
# print(dict1)

# 字典的遍历
# 定义非空字典
# info = {
#     "name": "tom",
#     "age": 18,
#     "gender": "男"
#     }
# # 遍历获取字典中所有键
# for i in info.keys():
#     print(f"字典的键是：{i}")
# # 遍历获取字典中所有值
# for i in info.values():
#     print(f"字典的值是：{i}")
# # 遍历获取字典的键和值
# for k, v in info.items():
#     print(f"{k} = {v}")

# 集合的使用
# 1.定义空集合
# info = set()
# print(info)
# 2.集合中添加元素："a"
# info.add("a")
# info.add("b")
# print(info)
# 定义非空字符串
# var = "abcdeabdcdf"
# 3.打印非重复的元素
# print(set(var))
# tmp = list(set(var))
# print(tmp)
# print("".join(tmp))

# 切片操作
# 作用：按照指定要求获取一段数据
# 定义非空字符串
# name = "abcdefgh"
# 获取cde
# print(name[2:5])
# print(name[2:5:1])
# print(name[‐6:‐3])
# print(name[‐6:‐3:1])
# 获取defgh的字符
# print(name[3:8])
# print(name[3:])
# print(name[‐5:])
# 获取abc的字符
# 获取ace的字符
# print(name[0:5:2])
# print(name[:5:2])
# # 获取hgfedcba
# print(name[::‐1])

# 序列长度
# 定义非空字符串
# info = "abcdefgh"
# info1 = "Hello Python"
# # 统计字符元素个数（长度）
# print(len(info)) # 8
# print(len(info1)) # 12
# # 定义非空列表
# info2 = [11, "aa", 1.88, (1, 2, 3), ["aa", "bb"]]
# print(len(info2)) # 5
# # 定义非空元组
# info3 = (11, "aa", 1.88)
# print(len(info3)) # 3
# # 定义非空字典
# info4 = {"name": "tom", "age": 18, "gender": "男"}
# print(len(info4))

# 清空序列
# info2 = [11, "aa", 1.88, (1, 2, 3), ["aa", "bb"]]
# # 清空列表数据
# info2.clear()
# # 查看原有列表
# print(info2)
# info4 = {"name": "tom", "age": 18, "gender": "男"}
# # 清空字典数据
# info4.clear()
# # 查看原有字典
# print(info4)

# 综合案例
# 定义变量：列表
login_data1 = [
    ["13800000001", "123456", "8888", "登录成功"],
    ["13800000001", "1234", "8888", "密码错误"],
    ["13800000001", "123456", "0000", "验证码错误"]
    ]
# 定义变量：元组
login_data2 = (
    ("13800000001", "123456", "8888", "登录成功"),
    ("13800000001", "1234", "8888", "密码错误"),
    ("13800000001", "123456", "0000", "验证码错误")
    )
# 定义变量：列表元组
login_data3 = [
    ("13800000001", "123456", "8888", "登录成功"),
    ("13800000001", "1234", "8888", "密码错误"),
    ("13800000001", "123456", "0000", "验证码错误")
    ]
# 定义变量：列表字典
login_data4 = [
    {"username": "13800000001", "password": "123456", "code": "8888", "result": "登录成功"},
    {"username": "13800000001", "password": "666666", "code": "8888", "result": "密码错误"},
    {"username": "13800000001", "password": "123456", "code": "0000", "result": "验证码错误"}
    ]
# 遍历数据3
for j in login_data3:
    # j = ("13800000001", "123456", "8888", "登录成功")
    print(f"用户名：{j[0]} 密码：{j[1]} 验证码：{j[2]} 期望结果：{j[3]}")
# 遍历数据4
for i in login_data4:
    print(f"用户名：{i.get('username')} 密码：{i.get('password')} 验证码：{i.get('code')} 期望结果：{i.get('result')}")

